﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

namespace UNSWThink
{
   /// <summary>
   /// Object that contains all of the global and static definitions, enums, and types used 
   /// by this project
   /// </summary>
   public class Defs
   {
      /// <summary>
      /// Length of time that a thread is to sleep (5s)
      /// </summary>
      public const int THREAD_SLEEP_LENGTH = 5000;

      /// <summary>
      /// Default string that should be used when a string cannot be empty or null
      /// </summary>
      public const string DEFAULT_STRING = "NONE";

      /// <summary>
      /// Default string that should be used when a string is 'not applicable'
      /// </summary>
      public const string DEFAULT_NA_STRING = "N/A";

      /// <summary>
      /// Default data grid view cell background colour
      /// </summary>
      public static Color EDIT_COLOUR = Color.Red;

      /// <summary>
      /// Default data grid view cell foreground colour
      /// </summary>
      public static Color NORMAL_COLOUR = Color.Empty;

      /// <summary>
      /// Default value for a no course option which should be '1' since the database
      /// should have been set up so that the first course is a 'no course' course
      /// </summary>
      public const int NO_COURSE_ID = 1;

      /// <summary>
      /// Default number for a miscellaneous week
      /// </summary>
      public const int MISC_WEEK_INT = -2;

      /// <summary>
      /// Default number for a revision week
      /// </summary>
      public const int REV_WEEK_INT = -1;

      /// <summary>
      /// Default string for a miscellaneous week
      /// </summary>
      public const string MISC_WEEK_STRING = "Misc. Week";

      /// <summary>
      /// Default string for a revision week
      /// </summary>
      public const string REV_WEEK_STRING = "Revision Week";

      /// <summary>
      /// Default string for a week. Should be used as a prefix to a week string
      /// </summary>
      public const string WEEK_STRING = "Week ";

      /// <summary>
      /// Standard boolean 'true' in string format
      /// </summary>
      public const string TFQ_TRUE = "true";

      /// <summary>
      /// Standard boolean 'false' in string format
      /// </summary>
      public const string TFQ_FALSE = "false";

      /// <summary>
      /// String to represent the format of a date and time string.
      /// Should be used when returning a string representation from a DateTime
      /// </summary>
      public const string DATE_TIME_STRING_FORMAT = "dd/MM/yyyy HH:mm:ss";

      /// <summary>
      /// Add mode for adding records
      /// </summary>
      public const bool ADD_MODE = true;

      /// <summary>
      /// Edit mode for editing records
      /// </summary>
      public const bool EDIT_MODE = false;

      /// <summary>
      /// Response mode for setting ViewResponsesForm to view responses
      /// </summary>
      public const bool RESPONSE_MODE = true;

      /// <summary>
      /// Enquiry mode for setting ViewResponsesForm to view enquiries
      /// </summary>
      public const bool ENQUIRY_MODE = false;

      /// <summary>
      /// Array of column names that exist in the 'Class' table
      /// </summary>
      public static string[] CLASS_COLUMN_NAMES = { "id", "course", "starttime", "finishtime", "week", "name", "comments" };

      /// <summary>
      /// Array of column names that exist in the 'ClassAccount' table
      /// </summary>
      public static string[] CLASS_ACCOUNT_COLUMN_NAMES = { "id", "class", "password" };

      /// <summary>
      /// Array of column names that exist in the 'Question' table
      /// </summary>
      public static string[] QUESTION_COLUMN_NAMES = { "id", "class", "number", "description", "type", "image" };

      /// <summary>
      /// Array of column names that exist in the 'Answer' table
      /// </summary>
      public static string[] ANSWER_COLUMN_NAMES = { "id", "question", "description", "iscorrect", "image" };

      /// <summary>
      /// Array of column names that exist in the 'Response' table
      /// </summary>
      public static string[] RESPONSE_COLUMN_NAMES = { "id", "question", "description", "type"};

      /// <summary>
      /// Array of column names that exist in the 'Response' table
      /// </summary>
      public static string[] ENQUIRY_COLUMN_NAMES = { "id", "class", "time", "description"};
   }

   /// <summary>
   /// Enum of the valid types for a question
   /// </summary>
   public enum QuestionType
   {
      /// Multiple Choice Question
      MCQ = 1,
      /// Open question
      OPN = 2,
      /// True or False Question
      TFQ = 3
   }

   /// <summary>
   /// Enum of the valid types for an account
   /// </summary>
   public enum AccountType
   {
      /// Administrator
      ADM = 1,
      /// Instructor
      INS = 2,
      /// Tutor
      TUT = 3,
      /// Student
      STU = 4,
      /// Other (not classified by previous types)
      OTH = 5
   }

   /// <summary>
   /// Enum of the valid values for a term
   /// </summary>
   public enum SessionType
   {
      /// Session 1
      S1 = 1,
      /// Session 2
      S2 = 2,
      /// Winter session?
      X1 = 3,
      /// Summer session?
      X2 = 4
   }

   /// <summary>
   /// States of data retrieval. Used for response and enquiry  retrieval threads
   /// </summary>
   public enum RetrievalState
   {
      /// Initial state
      Idle = 1,
      /// Initial retrieval state
      Starting = 2,
      /// Retrieval state
      Running = 3,
      /// Final state
      Stopping = 4
   }

   /// <summary>
   /// Object used to hold response information
   /// </summary>
   public class ResponseTotal
   {
      /// description of the answer
      public string Answer;
      /// number of responses that are equal to the answer
      public int CurrentTotal;

      /// <summary>
      /// Default constructor
      /// </summary>
      public ResponseTotal(string answer)
      {
         this.Answer = answer;
         this.CurrentTotal = 0;
      }
   }

   public class QuestionTotal
   {
      public int QuestionID;
      public int QuestionNum;
      public ArrayList Totals;

      public QuestionTotal(int questionID, int questionNum)
      {
         this.QuestionID = questionID;
         this.QuestionNum = questionNum;
         this.Totals = new ArrayList();
      }
   }

   public class QuestionResponse
   {
      public int QuestionID;
      public int QuestionNum;
      public DataTable Responses;

      public QuestionResponse(int questionID, int questionNum)
      {
         this.QuestionID = questionID;
         this.QuestionNum = questionNum;
         this.Responses = new DataTable();
      }
   }
}
